﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using RayD.Core;
using RayD.Repository.Core;

namespace RayD.Repository.Entites.SystemModule
{
    [Table("BASE_DATAITEMDETAIL")]
    public class DataItemDetailEntity : BaseTreeModel<DataItemDetailEntity>
    {
        #region 实体成员
        /// <summary>
        /// 明细主键
        /// </summary>
        /// <returns></returns>
        [Key]
        [Column("B_ITEMDETAILID")]
        public string B_ItemDetailId { get; set; }
        /// <summary>
        /// 分类主键
        /// </summary>
        /// <returns></returns>
        [Column("B_ITEMID")]
        public string B_ItemId { get; set; }
        /// <summary>
        /// 父级主键
        /// </summary>
        /// <returns></returns>
        [Column("B_PARENTID")]
        public string B_ParentId { get; set; }
        /// <summary>
        /// 编码
        /// </summary>
        /// <returns></returns>
        [Column("B_ITEMCODE")]
        public string B_ItemCode { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        /// <returns></returns>
        [Column("B_ITEMNAME")]
        public string B_ItemName { get; set; }
        /// <summary>
        /// 值
        /// </summary>
        /// <returns></returns>
        [Column("B_ITEMVALUE")]
        public string B_ItemValue { get; set; }
        /// <summary>
        /// 简拼
        /// </summary>
        /// <returns></returns>
        [Column("B_SIMPLESPELLING")]
        public string B_SimpleSpelling { get; set; }
        /// <summary>
        /// 排序码
        /// </summary>
        /// <returns></returns>
        [Column("B_SORTCODE")]
        public int? B_SortCode { get; set; }
        /// <summary>
        /// 有效标志
        /// </summary>
        /// <returns></returns>
        [Column("B_ENABLEDMARK")]
        public EnabledMark? B_EnabledMark { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        /// <returns></returns>
        [Column("B_DESCRIPTION")]
        public string B_Description { get; set; }
        /// <summary>
        /// 创建日期
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEDATE")]
        public DateTime? B_CreateDate { get; set; }
        /// <summary>
        /// 创建用户主键
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEUSERID")]
        public string B_CreateUserId { get; set; }
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEUSERNAME")]
        public string B_CreateUserName { get; set; }
        /// <summary>
        /// 修改日期
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYDATE")]
        public DateTime? B_ModifyDate { get; set; }
        /// <summary>
        /// 修改用户主键
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYUSERID")]
        public string B_ModifyUserId { get; set; }
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYUSERNAME")]
        public string B_ModifyUserName { get; set; }
        #endregion

        #region 扩展操作
        /// <summary>
        /// 新增调用
        /// </summary>
        public void Create()
        {
            if (this.B_ParentId.IsEmpty())
            {
                this.B_ParentId = "0";
            }
            if (this.B_EnabledMark.IsEmpty())
            {
                this.B_EnabledMark = EnabledMark.Enabled;
            }
            this.B_ItemDetailId = Guid.NewGuid().ToString();
            this.B_CreateDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_CreateUserId = userInfo.userId;
            this.B_CreateUserName = userInfo.realName;
        }
        /// <summary>
        /// 编辑调用
        /// </summary>
        public void Modify()
        {
            if (this.B_ParentId.IsEmpty())
            {
                this.B_ParentId = "0";
            }
            this.B_ModifyDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_ModifyUserId = userInfo.userId;
            this.B_ModifyUserName = userInfo.realName;
        }
        #endregion

        #region 树型配置
        [NotMapped]
        public override string id { get => this.B_ItemDetailId; }
        [NotMapped]
        public override string parentId { get => this.B_ParentId; }
        //[NotMapped]
        //public override string value { get => this.B_ItemValue; }
        [NotMapped]
        public override string label { get => this.B_ItemName; }
        #endregion
    }
}
